<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            background-color: pink;
        }
    </style>
</head>
<body>
    <button>显示与隐藏</button>
    <div></div>

    <script>
        var btn = document.querySelector('button')
        var div = document.querySelector('div')
        var flag = true //显示
        btn.onclick = function() {
            if(flag) {
                //让他隐藏
                div.style.display = 'none'
                flag = false

            } else {
                //让他显示
                div.style.display = 'block'
                flag = true
            }
        }
    </script>
</body>
</html>